﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="FTradeBalanceAddImport.aspx.cs" Inherits="IHISCETeim.Web.MachineSys.FTradeModel.ImortDate.FTradeBalanceAddImport" %>

<div class="pageContent">
	<form  method="post" action="FTradeModel/ImortDate/FTradeBalanceAddImport.aspx?ajaxmethod=add&FCatheringId=<%=FCatheringId %>&JiHao=<%=JiHao %>" class="pageForm required-validate" onsubmit="return validateCallback(this, navTabAjaxDone);" >
		<div class="pageFormContent" layoutH="56">
            <h2 style="clear:both; padding:5px; border-bottom:1px solid #B8D0D6; margin-bottom:5px; ">
                收款基本信息
            </h2>
                <label style=" font-weight:bold; color:Olive;">收款标题：</label>
				<input name="FCTitle" type="text" class="required" value="<%=obj.FCTitle %>" size="80" readonly />
                <span class="unit">(做为标签方便使用)</span>
                 <div class="divider"></div>
                <p>
				    <label>经 销 商：</label>
                    <input name="JingXiaoShang" type="text" value="<%=obj.JingXiaoShang %>" readonly />
			    </p>
                <p>
				    <label>收款日期：</label>
				    <input name="ShoukuanRiQi" class="date required" type="text" value="<%=obj.ShoukuanRiQi.ToString("yyyy-MM-dd") %>" alt="" readonly/>
			    </p>
               <div class="divider"></div>
                <p>
				    <label>金     额：</label>
				    <input  name="JinE" class="required inputFloat" type="text" value="<%=obj.JinE %>" size="" alt="" readonly/>
                    <span class="unit">元</span>
			    </p>
                <p>
                    <label>款项类型:</label>
                    <input  name="KuanXiangLeiXing"  value="<%=obj.KuanXiangLeiXing %>" readonly/>
                    
                </p>
                <p>
                    <label>剩余金额:</label>
                    <input id="FTradeBalanceAdd_ShengYuJinE"  name="ShengYuJinE"  value="<%=obj.ShengYuJinE %>" readonly/>                    
                </p>
                <p>
                    <label>来源:</label>
                    <input  name="SourceTag"  value="<%=obj.SourceTag %>" readonly/>                    
                </p>
                <p>
                    <label>是否做过调帐:</label>
                    <input  name="SourceTag"  value="<%=obj.IsAdjustable?"是":"否" %>" readonly/>                    
                </p>
            <div class="divider"></div>
            <h2 style="clear:both; padding:5px; border-bottom:1px solid #B8D0D6; margin-bottom:5px; margin-top:15px; line-height:26px;">
                本次冲帐
                &nbsp;&nbsp;
                <a style=" float:right;" class="button" href="javascript:openFTradeAgeDetailLookUpList();"><span>添加需冲帐记录</span></a>
            </h2>
            <div  style=" clear:both;">
                <table id="FTradeBalanceAdd_AddBalanceList" class="list" width="100%" layouth="90" >
                <thead>
                    <tr  >                
                        <th width="80" >机号</th>
                        <th>款项名称</th>                
                        <th width="80">金额</th> 
                        <th width="120">到期日</th> 
                        <th>已付</th> 
                        <th>本次冲帐</th> 
                        <th>操作</th>             
                    </tr>
                 </thead>
                 <tbody>
                    <%--<tr >
				        <td><input type="text" readonly value="[机号]" /></td>
				        <td><input type="text" readonly value="[款项名称]" /></td>
				        <td><input type="text" readonly value="[金额]" /></td>
                        <td><input type="text" readonly value="[到期日]" /></td>
                        <td><input type="text" readonly value="[已付]" /></td>
                        <td>
                            <input type="hidden" name="FTradeAgeId" value="[应收帐款明细]" />
                            <input type="text" name="BalanceMoney" value="[本次冲帐]" />
                        </td>
			            <td>
					        <a href="javascript:onAgetDetailSelectAddDelete(this)" title="删除">删除</a>
				        </td>
			        </tr>--%>
                 </tbody>
                 <tfoot>
                    <tr>
                        <td colspan="5" style="text-align:right;">
                        <span style="color:Red; line-height:25px;" id="FTradeBalanceAdd_AddBalanceList_AllBalance_Hit"></span>
                        本次冲帐总计:
                        </td>
                        <td colspan="2" >
                            <input type="text" id="FTradeBalanceAdd_AddBalanceList_AllBalance" size="10" readonly value="0" />
                            
                        </td>
                        
                    </tr>
                 </tfoot>
                 </table>           
            </div>
            <script>
                $(document).ready(function () {
                    if ('<%=obj.State %>' == '不可用') {
                        alertMsg.error('对不起,此收款记录为系统生成,无法进行冲帐操作！');
                        navTab.closeCurrentTab();
                        return;
                    }
                    $("#FTradeBalanceAddbtnSave").hide();
                    openFTradeAgeDetailLookUpList();

                })
                function openFTradeAgeDetailLookUpList() {
                    var rel = "FTradeAgeDetailLookUpList";
                    var url = "FTradeModel/FTradeAgeDetailLookUpList.aspx?JingXiaoShang=" + encodeURI("<%=obj.JingXiaoShang %>") + "&JiHao=<%=JiHao %>";
                    var title = "选择可冲帐的记录";
                    var options = { width: 850, height: 450, max: false, mask: true, maxable: false, minable: false, fresh: true, resizable: false, drawable: true };
                    top.$.pdialog.open(url, rel, title, options);
                }

                function onAgetDetailSelectAdd(objId, rowDate) {
                    var $BalanceMoney = $(objId).val();
                    var $AddBalanceListTbody = $("#FTradeBalanceAdd_AddBalanceList").find("tbody");
                    var rowExist = $AddBalanceListTbody.find("#FTradeBalanceAdd_AddBalanceList_Row" + rowDate.FTradeAgeId).attr("id");
                    if (rowExist != undefined) {
                        alertMsg.warn("对不起,已添加到要冲帐的记录中,请选择其它冲帐记录");
                        return;
                    }
                    var htmltemp = "<tr id='FTradeBalanceAdd_AddBalanceList_Row" + rowDate.FTradeAgeId + "' >" +
				                    "<td><input type=\"text\" class='readonly'  size='10' readonly value=\"[机号]\" /></td>" +
				                    "<td><input type=\"text\" class='readonly' size='10' readonly value=\"[款项名称]\" /></td>" +
				                    "<td><input type=\"text\" class='readonly' size='10' readonly value=\"[金额]\" /></td>" +
                                    "<td><input type=\"text\" class='readonly' size='10' readonly value=\"[到期日]\" /></td>" +
                                    "<td><input type=\"text\" class='readonly' size='10' readonly value=\"[已付]\" /></td>" +
                                    "<td>" +
                                    "    <input type=\"hidden\" name=\"FTradeAgeId\" value=\"[应收帐款明细]\" />" +
                                    "    <input type=\"text\" size='10' name=\"BalanceMoney\" value=\"[本次冲帐]\" />" +
                                    "</td>" +
			                        "<td>" +
					                "    <a href=\"#\" title=\"删除\">删除</a>" +
				                    "</td>" +
			                    "</tr>";
                    var addHtml = htmltemp.replace("[机号]", rowDate.JiHao).replace("[款项名称]", rowDate.ShowTitle).replace("[机号]", rowDate.JiHao).replace("[金额]", rowDate.JinE).replace("[到期日]", rowDate.DaoQiRi).replace("[已付]", rowDate.YiChongJinE).replace("[应收帐款明细]", rowDate.FTradeAgeId).replace("[本次冲帐]", $BalanceMoney);
                    $AddBalanceListTbody.append($(addHtml).find("a").click(function () {
                        onAgetDetailSelectAddDelete($(this));
                    }).end().find(":text[name='BalanceMoney']").change(function () {
                        onAgetDetailSelectAddChange($(this));
                    }).end()
                    );
                    //
                    onAgetDetailSelectAddChange();
                }

                function onAgetDetailSelectAddDelete(aObj) {


                    aObj.closest("tr").remove();

                    onAgetDetailSelectAddChange();
                }
                function onAgetDetailSelectAddChange() {
                    var $AddBalanceListTbody = $("#FTradeBalanceAdd_AddBalanceList").find("tbody");
                    var AllBalance = 0;
                    $AddBalanceListTbody.find("input[name='BalanceMoney']").each(function () {
                        // var $AllBalance = $("#FTradeBalanceAdd_AddBalanceList_AllBalance").val();
                        AllBalance = AllBalance + parseFloat($(this).val());
                    })
                    var $AddBalanceList_AllBalance = $("#FTradeBalanceAdd_AddBalanceList_AllBalance");
                    $AddBalanceList_AllBalance.val(AllBalance); //
                    //剩余金额
                    var $ShengYuJinE = $("#FTradeBalanceAdd_ShengYuJinE").val();
                    if (parseFloat($ShengYuJinE) < AllBalance) {
                        $AddBalanceList_AllBalance.css("color", "red");
                        $("#FTradeBalanceAdd_AddBalanceList_AllBalance_Hit").html("冲帐金额大于剩余金额,请修改");
                        $("#FTradeBalanceAddbtnSave").hide();
                    }
                    else {
                        $AddBalanceList_AllBalance.css("color", "");
                        $("#FTradeBalanceAdd_AddBalanceList_AllBalance_Hit").html("");
                        $("#FTradeBalanceAddbtnSave").show();
                    }
                }
            </script>
        </div>
		<div class="formBar">
			<ul>
				
				<li id="FTradeBalanceAddbtnSave"><div class="buttonActive"><div class="buttonContent"><button type="submit"  >保存</button></div></div></li>
				<li>
					<div class="button"><div class="buttonContent"><button type="button" class="close">取消</button></div></div>
				</li>
			</ul>
		</div>
	</form>
</div>